//
//  PKRootRightViewController.m
//  PianKe
//
//  Created by mingtao on 15/9/25.
//  Copyright (c) 2015年 mingtao. All rights reserved.
//

#import "PKRootRightViewController.h"

#import "PKBaseViewController.h"

@interface PKRootRightViewController ()

@property (nonatomic,strong)NSArray *classArray;
@property (nonatomic,strong)PKBaseViewController *baseVC;

@property(nonatomic,strong)UINavigationController *navi;

@end

@implementation PKRootRightViewController

-(NSArray *)classArray
{
    if (!_classArray) {//PKGroupMainViewController
        _classArray = @[@"PKReadMainViewController",@"PKRadioMainViewController",@"PKGroupMainViewController",@"PKProductMainViewController",@"PKReadingViewController"];
    }
    return _classArray;
}

//ARC和MRC都不能手动调用dealloc方法，但是可以重写，ARC重写时候不能再dealloc方法内部调用【super dealloc】,一般会用于移除观察者，代理对象置空等
- (void)dealloc
{
    NSLog(@"%@被释放了",self);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    UIButton *button=[UIButton buttonWithType:(UIButtonTypeSystem)];
//    
//    button.frame = CGRectMake(5, 70, 30, 30);
//    
//    button.backgroundColor = [UIColor redColor];
//    
//    [button addTarget:self action:@selector(changgeFrame) forControlEvents:UIControlEventTouchUpInside];
//    
//    [self.view addSubview:button];
    
    _baseVC=[[NSClassFromString(self.classArray[0])alloc]init];
    //创建一个导航控制器，让它去管理将要显示的详细界面，这样将要显示的界面才有push功能,因为导航控制器需要一直存在，所以可以把它设置一个属性
    _navi=[[UINavigationController alloc]initWithRootViewController:_baseVC];
    
    //隐藏导航栏
    _navi.navigationBar.hidden = YES;
    
    _baseVC.changeFrameVC = self;
   // [self changgeFrame];
    [self.view addSubview:_navi.view];
}



//button点击的方法
-(void)changgeFrame
{
    CGRect newFrame = self.view.frame;
    
    if (newFrame.origin.x==0) {
        newFrame.origin.x = WIHES-40;
    }else
    {
         newFrame.origin.x = 0;
    
    }
    
   [UIView animateWithDuration:.5 animations:^{
       self.view.frame = newFrame;
   }];
    
    

}

-(void)changeViewWithIndex:(NSInteger)index
{
//    switch (index) {
//        case 0:
//            //1.创建电台控制器
//            //2.吧电台控制的View添加到自己的视图上面
//            
//            
//            break;
//            case 1:
//            //1.创建阅读控制器
//            //2.吧阅读控制器的view添加到自己的视图上面
//            
//            break;
//            
//        case 2:
//            //创建社区控制器
//            //2.把社区的控制器view添加到自己视图上面
//            break;
//            
//        case 3:
//            //把良品控制器
//            //把良品的控制器view添加大自己视图上面
//            
//            break;
//            
//        default:
//            break;
//    }
    
    //用NSClassFromString函数通过字符串获取某个类，然后动态的创建不同控制器，同时使用多台的思想，让弗雷指针接收子类
    [_navi.view removeFromSuperview];
    _baseVC=[[NSClassFromString(self.classArray[index])alloc]init];
    
    
    
    
//    _baseVC.changeFrameVC = self;
//    [self changgeFrame];
    
    _navi=[[UINavigationController alloc]initWithRootViewController:_baseVC];
    
    _baseVC.changeFrameVC = self;
     [self changgeFrame];
    
    _navi.navigationBar.hidden = YES;
    [self.view addSubview:_navi.view];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
